# Build recipe for u-boot-tools.
#
# Copyright (C) 2019 Kevin "The Nuclear" Bloom, <nuclearkev@dragora.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Based on recipes written by Mateus P. Rodrigues, <mprodrigues@dragora.org>
# and Matias Fonzo, <selk@dragora.org>.

program=u-boot
version=2019.07
release=1

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=ftp://ftp.denx.de/pub/${program}/$tarname

description="
u-boot-tools - tools to build kernel images

u-boot is for booting devices. The tools are useful for building images for C201.
"

homepage=http://www.denx.de/wiki/U-Boot/WebHome
license="Custom"

# Source documentation
docs="README"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    make defconfig
    make -j${jobs} V=1 tools-all

    install -m 755 -d ${destdir}/usr/bin
    install -m 755 -t ${destdir}/usr/bin/ ./tools/mkimage
    install -m 755 -t ${destdir}/usr/bin/ ./tools/mkenvimage
    install -m 755 -t ${destdir}/usr/bin/ ./tools/env/fw_printenv
    install -m 755 -t ${destdir}/usr/bin/ ./tools/img2srec
    install -m 755 -t ${destdir}/usr/bin/ ./tools/dumpimage
    install -m 755 -t ${destdir}/usr/bin/ ./tools/netconsole
    install -m 755 -t ${destdir}/usr/bin/ ./tools/jtagconsole
    install -m 755 -t ${destdir}/usr/bin/ ./tools/ncb
    ln -s fw_printenv ${destdir}/usr/bin/fw_setenv
    install -m 644 -D ./doc/mkimage.1 $srcdir/usr/share/man/man1/mkimage.1

    # Delete index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"

    for file in $docs
    do
        if test -e $file
        then
            cp -p $file "${destdir}${docsdir}"
        fi
    done
}
